package com.situ.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.situ.dao.IvInvoiceDao;
import com.situ.entity.IvIninvoice;


import com.situ.entity.FuHeFaPiao;
import com.situ.entity.FuHeFaPiaomingxi;
import com.situ.entity.IvIninvoice;
import com.situ.entity.SyEmp;

import com.situ.dao.IvInvoiceDao;
import com.situ.entity.IvIninvoice;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.situ.service.IvInvoiceService;
import com.situ.entity.IvInvoice;


import javax.servlet.http.HttpServletRequest;

import java.beans.PropertyEditor;
import java.text.DateFormat;
import java.text.SimpleDateFormat;


import java.util.*;

/**
 * IvInvoice的路由接口服务
 *
 * @author 胡文
 */
@Controller
public class IvInvoiceController {



	/** IvInvoiceService服务 */
	@Autowired
	private IvInvoiceService ivInvoiceService;
	 @Autowired(required = false)
	    private IvInvoiceDao ivInvoiceDao;
	
	@InitBinder
	public void dateconvert(WebDataBinder bind) {
		DateFormat format=new SimpleDateFormat("yyyy-MM-dd");
		PropertyEditor n=new CustomDateEditor(format, true);
		bind.registerCustomEditor(Date.class, n);
	}
	//发票情况汇总报表
	@RequestMapping("inv_invoiceReportUse.html")
	public String queryzong(Map map,FuHeFaPiao fuhe,HttpServletRequest request){
		List<Map> zong=ivInvoiceService.findhuizonggaoji(fuhe);
		//查询总金额
		List<Map> zmoney=ivInvoiceService.queryzmoney();
		//查询员工下拉框
		List<SyEmp> elist=ivInvoiceService.queryxialaemp();
		map.put("zong", zong);
		map.put("zmoney", zmoney);
		map.put("elist", elist);

		return "page/inv_invoiceReportUse.html";
	}

	//发票情况明细表
	@RequestMapping("inv_invoiceReportUse1.html")
	public String querymingxi(Map map,@RequestParam(defaultValue ="1",required = false) int startPage ,
							          @RequestParam(defaultValue = "5",required = false) int PageSize,FuHeFaPiao fuhe){
		//全查加分页
		PageHelper.startPage(startPage, PageSize);
		List<Map> mxlist=ivInvoiceService.findmingxigaoji(fuhe);
		PageInfo pageInfo = new PageInfo<Map>(mxlist,5);

		//查询总张数
		//List<Map> zong=ivInvoiceService.queryhuizong();
		int counts=ivInvoiceService.queryzshu();
		//查询已用的总张数
        int used=ivInvoiceService.queryusezshu();
        //查询作废的总张数
		int zuofei=ivInvoiceService.queryzuofeizshu();
		//查询总金额
		int zmoney=ivInvoiceService.queryzjmoney();
		//查询员工下拉框
		List<SyEmp> elist=ivInvoiceService.queryxialaemp();

		map.put("pageInfo", pageInfo);
		map.put("startPage", startPage);
		map.put("PageSize", PageSize);
		map.put("mxlist", mxlist);
		map.put("counts", counts);
		map.put("used", used);
		map.put("zuofei", zuofei);
		map.put("zmoney", zmoney);
		map.put("elist", elist);
		return "page/inv_invoiceReportUse1.html";
	}
	
	//销账汇总报表
	@RequestMapping("inv_invoiceReportMoneySum.html")
	public String queryzong(Map map) {
		//查询一个汇总
		List<Map> zlist=ivInvoiceService.queryzong();
		//查询分类用水量和销账金额
		List<Map> fenleiz=ivInvoiceService.queryyongshuixiaoz();
		map.put("zlist", zlist);
		map.put("fenleiz", fenleiz);
		return "page/inv_invoiceReportMoneySum.html";
	}
	//销账明细报表
	@RequestMapping("inv_invoiceReportMoneyDetail.html")
	public String queryxiaozhanmingxi(Map map,
			@RequestParam(defaultValue ="1",required = false) int startPage ,
            @RequestParam(defaultValue = "5",required = false) int PageSize,FuHeFaPiaomingxi fuhe) {
		//查询一个总的明细报表
		PageHelper.startPage(startPage, PageSize);
		List<Map> zmingxi=ivInvoiceService.Findxiaozhanmingxigaoji(fuhe);//queryxiaozhanmingxi
		PageInfo pageInfo = new PageInfo<Map>(zmingxi,5);
		 
		map.put("zmingxi", zmingxi);
		map.put("pageInfo", pageInfo);
        map.put("startPage", startPage);
        map.put("PageSize", PageSize);
		return "page/inv_invoiceReportMoneyDetail.html";
	}
	/**
	 * 查询所有IvInvoice数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "queryIvInvoice", produces = {"application/json;charset=UTF-8"})
	public String find(IvInvoice value,Map map) {
		 List<IvInvoice> list= ivInvoiceService.find(value);
         map.put("items",list);
         return "页面名称自己改";
	}
	
	
  
   


    /**
     * 查询所有IvInvoice数据的方法
     *
     * @param
     * @return
     */
    @GetMapping("/queryIvInvoice")
    public String find(@RequestParam(defaultValue = "1", required = false) int startPage,
                       @RequestParam(defaultValue = "5", required = false) int PageSize, Map map) {
        PageSize = 5;
        PageHelper.startPage(startPage, PageSize);
        List<Map> list = ivInvoiceService.queryAll();
        PageInfo pageInfo = new PageInfo<>(list);
        map.put("pageInfo", pageInfo);
        map.put("startPage", startPage);
        map.put("PageSize", PageSize);
        map.put("list", list);
        return "inv_invoiceManage.html";
    }


    /**
     * 通过id查询IvInvoice数据的方法
     *
     * @return
     */
    @RequestMapping(value = "queryIvInvoiceById/{id}", produces = {"application/json;charset=UTF-8"})
    public String findOne(@PathVariable(name = "id") String id, Map map) {
        IvInvoice obj = ivInvoiceService.findOne(id);
        map.put("IvInvoice", obj);

        return "页面名称自己改";
    }

    /**
     * 插入IvInvoice属性不为空的数据方法
     *
     * @return
     */
    @RequestMapping(value = "saveIvInvoice", produces = {"application/json;charset=UTF-8"})
    public String save(IvInvoice value) {
        ivInvoiceService.saveNotNull(value);

        return "redirect:/queryIvInvoice";
    }


    /**
     * 更新IvInvoice属性不为空的数据方法
     *
     * @return
     */
    @RequestMapping(value = "updateIvInvoice", produces = {"application/json;charset=UTF-8"})
    public String update(IvInvoice value) {
        ivInvoiceService.updateNotNullById(value);
        return "redirect:/queryIvInvoice";
    }

    /**
     * 通过id删除IvInvoice数据方法
     *
     * @return
     */
    @RequestMapping(value = "delIvInvoiceById/{id}", produces = {"application/json;charset=UTF-8"})
    public String delete(@PathVariable(name = "id") String id) {
        ivInvoiceService.deleteById(id);
        return "redirect:/queryIvInvoice";
    }

}
